var empcode = $.getUrlParam('UserID')
window.onload = function() {
	$("#pwd-input").focus()
	$(".pwd-box").click(function() {
		$("#pwd-input").focus()
	})
	$("#btn").click(submit_change)
	var $input1 = $(".fake-box1 input");
	$("#pwd-input1").on("input", function() {
		var pwd = $(this).val().trim();
		for(var i = 0, len = pwd.length; i < len; i++) {
			$input1.eq("" + i + "").val(pwd[i]);
		}
		$input1.each(function() {
			var index = $(this).index();
			if(index >= len) {
				$(this).val("");
			}
		});
		if(len == 6) {
			//执行其他操作  
		}
	});
	var $input2 = $(".fake-box2 input");
	$("#pwd-input2").on("input", function() {
		var pwd = $(this).val().trim();
		for(var i = 0, len = pwd.length; i < len; i++) {
			$input2.eq("" + i + "").val(pwd[i]);
		}
		$input2.each(function() {
			var index = $(this).index();
			if(index >= len) {
				$(this).val("");
			}
		});
		if(len == 6) {
			//执行其他操作  
		}
	});var $input3 = $(".fake-box3 input");
	$("#pwd-input3").on("input", function() {
		var pwd = $(this).val().trim();
		for(var i = 0, len = pwd.length; i < len; i++) {
			$input3.eq("" + i + "").val(pwd[i]);
		}
		$input3.each(function() {
			var index = $(this).index();
			if(index >= len) {
				$(this).val("");
			}
		});
		if(len == 6) {
			//执行其他操作  
		}
	});
}

function submit_change() {
	var oldPassport = $('#pwd-input1').val();
	var newPassport = $('#pwd-input2').val();
	var newPassport2 = $('#pwd-input3').val();
	if(newPassport.toString().length >= 6 && newPassport2.toString().length >= 6 && oldPassport.toString().length >= 6) {
	newPassport = md5(newPassport)
	oldPassport = md5(oldPassport)
	newPassport2 = md5(newPassport2)
		if(newPassport == newPassport2) {
			var submitdata;
			submitdata = '<?xml version="1.0" encoding="utf-8"?>'
			submitdata += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
			submitdata += '<soap:Body>'
			submitdata += '<ModifyPass xmlns="http://tempuri.org/">'
			submitdata += '<empcode>' + empcode + '</empcode>'
			submitdata += '<passport>' + newPassport + '</passport>'
			submitdata += '<oldpassport>' + oldPassport + '</oldpassport>'
			submitdata += '</ModifyPass>'
			submitdata += '</soap:Body>'
			submitdata += '</soap:Envelope>'
			var datav = {
				data:submitdata,
				"SOAPAction": "http://tempuri.org/ModifyPass"
			}
			$.ajax({
				"url": "http://drpapi.kukahome.com:8099/Lookfor/trans",
				"type": 'POST',
				"async": false,
				"dataType": 'text',
				"data": datav,
				"success": function(data) {
					var msg = $(data).find("ModifyPassResult").text()
					msg = JSON.parse(msg)
					if(msg.error != 0) {
						$("#hint").html(msg.msg)
						$("#pwd-input1").val("")
						$(".fake-box1 input").val("")
						$("#pwd-input2").val("")
						$(".fake-box2 input").val("")
						$("#pwd-input3").val("")
						$(".fake-box3 input").val("")
					} else {
						$("#hint").html(msg.msg + "3s后跳转")
						setTimeout(function() {
							window.location.href = "index.html"
						}, 3000)
					}
				},
				"error": function(data) {
					$("#hint").html("网络出问题了")
				},
				headers: {
					"Content-Type": 'application/x-www-form-urlencoded',
//					"Content-Type": 'text/xml;charset=UTF-8',
//					"SOAPAction": "http://tempuri.org/ModifyPass",
				}
			});
		} else {
			$("#hint").html("两次密码不一致")
			$("#pwd-input2").val("")
			$(".fake-box2 input").val("")
			$("#pwd-input3").val("")
			$(".fake-box3 input").val("")
		}

	} else {
		$("#hint").html("请填写完整密码")
	}
}